﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Threading;


namespace MoiCare
{
    public partial class Service1 : ServiceBase
    {
        System.Timers.Timer t = null;


        Event_5s event_5s = new Event_5s();
        Event_1d event_1d = new Event_1d();

        public Service1()
        {
            InitializeComponent();           
        }

        protected override void OnStart(string[] args)
        {
            Log.log.Info("Start:"+DateTime.Now);
            t = new System.Timers.Timer(1000);
            t.Elapsed += new System.Timers.ElapsedEventHandler(theout);
            t.AutoReset = true;
            t.Enabled = true;

           
        }

        protected override void OnStop()
        {
            Log.log.Info("Stop:" + DateTime.Now);
            t.Dispose();
        }
        public void theout(object source, System.Timers.ElapsedEventArgs e)
        {
            //EventLog.WriteEntry(DateTime.Now.ToString());
            if (DateTime.Now > this.event_1d.Trigger) {
                ThreadPool.QueueUserWorkItem(new WaitCallback(this.event_1d.Handle), new DateTime());
                //this.event_1d.Handle();
                
            }
            if (DateTime.Now > this.event_5s.Trigger)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(this.event_5s.Handle), new DateTime());
                //this.event_5s.Handle();
            
            }
            

        }
    }
}
